import s from "./AudioManager"
import c from "./PlayerDataSys"
import u from "./AbTestMgr"
import p from "./OutsideGuideExperimentMgr"
import d from "./PeripheralSystemDataMgr"
import h from "./EventMgr"
import f from "./GameEventType"
import g from "./MatchGameEventType"
import y from "./frameworkManager"
import m from "./AdManager"
import _ from "./SdkHelper"
import v from "./EngineUtil"
import b from "./MathUtil"
import C from "./MatchGameData"
import T from "./MatchGameConfig"
import M from "./PageMgr"
import P from "./AdjustRichText"
import S from "./MatchGameSystemMgr"
import w, { OutSideLevelGuide, TravelEvent, VideoBuriedPoint } from "./PeripheralSystemMgr"
import A from "./UiManage"
import O from "./PandaTravel"
import I from "./TravelCityFlagItemCtrl"
import MathUtils from "./MathUtil"
import UiManager from "./UiManage"
import TravelCityFlagItemCtrl from "./TravelCityFlagItemCtrl"

var k = -200;
var D = {
    x: 178,
    y: 218
}

var R = 27.7;//旋转角度
var DUR = 3;//旋转时长
var FCOUNT = 15;//房子
var SCOUNT = 30;//树
var FRANDOM = 10;//房子随机
var SRANDOM = 5;//树随机
var TWEENSCALE = false;

const { ccclass, property } = cc._decorator;
@ccclass
export default class PandaTravelCtrl extends cc.Component {
    public Scaling = 1;
    public minScale = 1;
    public maxScale = 4;
    public moveOffset = 2;
    public increaseRate = 1e4;
    public fingerIncreaseRate = 1;
    public isMoving = false;
    public mapTouchList = [];
    public isStrict = true;
    public locked = false;
    public aniPaths = [];
    public mapLocalPos = null;
    public runCount = 0;
    public beginCount = 0;
    public finalMoveData = [];
    public mapDonePos = {
        x: 0,
        y: 0
    };
    public mapBoundLimit = {
        left: 0,
        right: 0,
        top: 0,
        bottom: 0
    };
    public canOpeateMap = false;
    public current = 0;
    public location = 1;
    public total = 0;
    public need = 0;
    public isInit = true;
    public aniLocalX = 0;
    public aniLocalY = 0;
    public isPlayingAni = false;
    public lastProgress = null;
    public mapPointArr = [];
    public movePointArr = [];
    public doneCityArr = [];
    public pandMoveSpeed = 0;
    public frame_time = 1 / 60;
    public makeMoneyOriginPos = null;
    public finalPro = null;
    public proSpeed = null;
    public enterGameOriginPos = null;
    public beiJingFlagShowCom = null;
    public clickStartGame = false;
    public ui;


    public onLoad() {
        this.onUILoad();
        this.dealOppoReview();
        h.trigger(f.SET_TOP_NODE_CANTOUCH, {
            isCanTouch: false
        });
        this.setEeffectTagNode();
        this.setGameTopShowNode();
        this.setMakeMoneyPos();
        this.setEnterGameBtnPos();
        this.addRollingNotice();
        this.initMap();
        this.addButtonListen();
        this.addEvent();
        this.initTestBtnShow();
        this.addMapPointPath();
        this.updateHotAirBallonState();
        this.checkShowGameStartNode(null, true);
        // this.checkShowTopNode();
        // this.dealAbTest();
        this.oppoReview();
        this.dealReplacePlaceName();
        this.adjustRich();
        this.ui.map.y = 0;
    };
    public adjustRich() {
        if ((u.getDmth2Ab1() || u.getDmth2Ab2()) && !this.ui.levelCrossTips.getComponent(P)) {
            this.ui.levelCrossTips.addComponent(P);
            this.ui.levelCrossTips.getComponent(P).init(354);
            this.ui.levelCrossTips.getComponent(P).adjustProTipSize();
        }
    };
    public dealReplacePlaceName() {
        return;
        var e = u.isDmthFlag(), t = C.isOppoChannel(), a = d.isHitOppoReviewBan();
        if (u.getDmth2Ab1()) {
            this.ui.placeBgNode.active = false;
            this.ui.placeNameNode.active = false;
        } else if (u.getDmth2Ab2()) {
            this.ui.placeBgNode.active = true;
            this.ui.placeNameNode.active = true;
            this.initPlaceName();
        } else if (e) if (a) {
            this.ui.placeBgNode.active = false;
            this.ui.placeNameNode.active = false;
        } else {
            this.ui.placeBgNode.active = true;
            this.ui.placeNameNode.active = true;
            this.initPlaceName();
        } else if (t) {
            this.ui.placeBgNode.active = false;
            this.ui.placeNameNode.active = false;
        } else {
            this.ui.placeBgNode.active = true;
            this.ui.placeNameNode.active = true;
            this.initPlaceName();
        }
    };
    public initPlaceName() {
        for (var e = this.ui.placeNameNode.children, t = 0; t < e.length; t++) {
            var a = e[t], o = d.getCityNameByCityId(t);
            a && o && (a.getComponent(cc.Label).string = o);
        }
    };
    public dealAbTest() {
        var e = u.isNoGqtcFlag();
        this.ui.maskNode.active = e;
    };
    public dealOppoReview() {
        if (d.isHitOppoReviewBan() && 0 == d.getOutsideGuideStep()) {
            d.setOutsideStep(p.OutSideLevelGuideExperimentStep.FUND_WITHDRAW);
            w.reportOutsideGuideStep(p.OutSideLevelGuideExperimentStep.FUND_WITHDRAW);
        }
    };
    public oppoReview() {
        if (C.isOppoChannel() || u.getDmth2Ab1()) {
            this.ui.drawSpineNode.setPosition(cc.v2(-33.356, 72.648));
            this.ui.drawSpineNode1.setPosition(cc.v2(-84, -22));
        } else {
            this.ui.drawSpineNode.setPosition(cc.v2(-39.693, 14.765));
            this.ui.drawSpineNode1.setPosition(cc.v2(-85, -78));
        }
    };
    public initTestBtnShow() {
        this.ui.btn_adSwitch.active = C.isEnableDebug();
    };
    public addMapPointPath() {
        var e = this;
        this.mapPointArr = d.getMapPointArr();
        0 == this.mapPointArr.length ? v.addLocalJson("travelPath/aniPath2", function (t) {
            e.mapPointArr = t;
            e.initCityFlag();
        }) : this.initCityFlag();
    };
    public addRollingNotice() {
        var e = d.getSrollMsgList();
        UiManager.loaderView(this.ui.rollingNode, "RollingNotice", e, 3, (e) => {
            d.setRollingNoticeNode(e);
        });
    };
    public onUILoad() {
        this.ui = this.node.addComponent(O);
    };
    public initMap() {
        this.node.setContentSize(cc.winSize);
        this.ui.mapContainer.setContentSize(cc.winSize);
        this.ui.mapContainer.width = 1.2 * cc.winSize.width;
        this.ui.mapContainer.height = 1.2 * cc.winSize.height;
        this.setMapLimitGround();
        this.ui.map.scale = this.minScale;

        for (let i = 0; i <= FCOUNT; i++) {
            let bg2: cc.Node = this.ui.map.getChildByName('bg2').getChildByName("earth");
            let d1: cc.Node = cc.instantiate(bg2.getChildByName("fangzi"));
            d1.active = true;
            d1.parent = bg2.getChildByName('fzp');
            d1.zIndex = 0;
            let randomAngleOffset = (Math.random() - 0.5) * FRANDOM; // Random value between -5 and 5
            d1.angle = 360 / FCOUNT * i + randomAngleOffset;
            d1.getChildByName("1").getComponent(cc.Animation).play();
            this._earthAnimationArr.push(d1.getChildByName("1").getComponent(cc.Animation));
        }

        for (let i = 0; i <= SCOUNT; i++) {
            let bg2: cc.Node = this.ui.map.getChildByName('bg2').getChildByName("earth");
            let d1: cc.Node = cc.instantiate(bg2.getChildByName("shu"));
            d1.parent = bg2.getChildByName('fzp1');;
            d1.active = true;
            d1.zIndex = 0;
            let randomAngleOffset = (Math.random() - 0.5) * SRANDOM; // Random value between -5 and 5
            d1.angle = 360 / SCOUNT * i + randomAngleOffset;
            d1.getChildByName("1").getComponent(cc.Animation).play();
            this._earthAnimationArr.push(d1.getChildByName("1").getComponent(cc.Animation));
        }

        let screenWidth = 900;
        this._earthAnimationArr.forEach(element => {
            let boundingBox = element.node.getBoundingBoxToWorld();
            element.node.active = boundingBox.y > 0 && !(boundingBox.xMax < 0 || boundingBox.xMin > screenWidth);
        });
    };

    private _earthAnimationArr: cc.Animation[] = [];
    public async initCityFlag() {
        this.setCityFlagScale();
        // this.ui.cityFlagNode.removeAllChildren();
        const e = await UiManager.loaderPrefab("TravelCityFlagItem");
        let worldpos = this.node.convertToNodeSpaceAR(this.node.parent.convertToWorldSpaceAR(cc.v3(0, 0, 0)));
        for (let t = 0; t < 7; t++) {
            // const a = cc.instantiate(e);
            const a: cc.Node = this.ui.cityFlagNode.children[t];
            let o = {
                x: 0,
                y: 0
            };
            // o = { x: t == 3 ? worldpos.x : t < 3 ? worldpos.x - Math.abs(3 - t) * 250 : worldpos.x + Math.abs(3 - t) * 250, y: -180 - Math.abs(3 - t) * 40};
            // if (t === 0) {
            //     o.x = k;
            //     o.y = -180;
            // } else {
            //     o = this.getCityFlagPos(t - 1);
            // }
            // this.ui.cityFlagNode.addChild(a);
            // a.addComponent(I);
            const i = a.getComponent(I);
            i.initData({
                cityId: t == 3 ? C.gameLevel : t < 3 ? C.gameLevel - Math.abs(3 - t) : C.gameLevel + Math.abs(3 - t),
                // posData: o,
                tagNode: this.ui.aniNode
            });
            // if (t === 31) {
            //     this.beiJingFlagShowCom = i;
            // }
        }

        this.checkOutSideGuide(true);
        this.recoverMapShow();
        this.onClockDaysUpdate();
    }
    public updateCityFlagShow() {
        for (var e = this.ui.cityFlagNode.children, t = 0; t < e.length; t++) {
            var a = e[t].getComponent(I) as TravelCityFlagItemCtrl, o = a.cityId;
            var d = C.gameLevel;
            a.initData({
                cityId: d + t - 3,
                // posData: o,
                tagNode: this.ui.aniNode
            });
            // 0 == o ? a.setLockShow(false) : o < this.location ? a.setLockShow(false) : a.setLockShow(true);
        }
    };
    public setCurrentAndNeed() {
        var e = d.getTravelLocation();
        if (e) {
            if (u.getIsLcsmzq() && e.location >= 31) {
                this.current = (1 - d.getToNextCityPercent()) * e.total;
                y.log("this.current-----", d.getToNextCityPercent(), e.total, this.current);
            } else this.current = e.current;
            this.need = d.getToNextCityPercent() * e.total;
        }
    };
    public onClockDaysUpdate() {
        d.getClockDays() >= 30 && u.getIsLcsmzq() && this.beiJingFlagShowCom.setBeiJingRewardFlagShow();
    };
    public getCityFlagPos(e) {
        var t = this.mapPointArr[e];
        if (t) return t[t.length - 1];
    };
    public addButtonListen() {
        UiManager.addButtonListen(this.ui.btn_adSwitch, this.adTestCallBack, this);
        UiManager.addButtonListen(this.ui.ballonNode, this.clickBallon, this, 0);
        UiManager.addButtonListen(this.ui.btn_startGame, this.startGameCallback, this, 0);
        UiManager.addButtonListen(this.ui.topNode, this.showTipToast, this);
        UiManager.addButtonListen(this.ui.btn_noGqtc, this.enterGame, this, 0);
        UiManager.addButtonListen(this.ui.levelCrossingNode, this.showTipToast, this);
    };
    public enterGame() {
        var e = this;
        this.ui.btn_noGqtc.getComponent(cc.Button).interactable = false;
        S.matchGameStart(null, function () {
            h.trigger(g.LOAD_MATCH_SCENE);
        }, function () {
            e.ui.btn_noGqtc.getComponent(cc.Button).interactable = true;
        });
    };
    public showEnterGameBtn() {
        this.setEnterGameCanTouch(true);
        this.setBallonCanTouch(true);
        this.canOpeateMap = true;
    };
    public canTouchEnterGameBtn() {
        this.ui.btn_noGqtc.getComponent(cc.Button).interactable = true;
    };
    public showTipToast() {
        M.showPage("TravelToastPage", {
            type: 1,
            cityId: null
        });
    };
    public start() { };
    public checkOutSideGuide(e?) {
        return;//去掉新手
        void 0 === e && (e = false);
        var t, a = d.getOutsideGuideStep(), o = u.isOptimizeTravelFundFlag();
        t = o ? p.OutSideLevelGuideExperimentStep.CLOCK_DAY : OutSideLevelGuide.CLOCK_DAY;
        if (!a || a && a < t) {
            var i = C.gameLevel;
            i = e ? i - 1 : i;
            u.isNoGqtcFlag() && (i = C.gameLevel - 1);
            if (a != OutSideLevelGuide.CONTINUE_GAME || o) {
                var r = d.checkGuideClock();
                a == (o ? p.OutSideLevelGuideExperimentStep.CONTINUE_GAME : OutSideLevelGuide.CASH_WITHDRAW) ? r ? d.showOutsideGuidePage() : e && h.trigger(f.SET_TOP_NODE_CANTOUCH, {
                    isCanTouch: true
                }) : d.showOutsideGuidePage();
            } else 2 == i ? M.showPage("OutsideLevelGuidePage") : e && h.trigger(f.SET_TOP_NODE_CANTOUCH, {
                isCanTouch: true
            });
        } else h.trigger(f.SET_TOP_NODE_CANTOUCH, {
            isCanTouch: true
        });
    };
    public startGameCallback(e) {
        var t = this;
        void 0 === e && (e = null);
        if (!e || e.isNeddPop) {
            e ? this.setGameStartCanTouch(true, false) : this.setGameStartCanTouch(true, true);
            this.setBallonCanTouch(true);
            this.canOpeateMap = true;
            if (!this.clickStartGame) {
                this.clickStartGame = true;
                S.matchGameStart(null, function () {
                    t.clickStartGame = false;
                    var e = C.getGameInfo();
                    console.log("MatchGameData.getGameInfo", e);
                    t.scheduleOnce(t.delayPlayFroceVideo, .5);
                    e.levelType !== T.GameLevelType.GoldCoin ? M.showPage("MatchGameTargetPage", {
                        level: e.level,
                        target: e.targetMatchData
                    }) : M.showPage("MatchGameMoneyPage", {
                        level: e.level,
                        target: e.targetMatchData
                    });
                }, function () {
                    t.clickStartGame = false;
                });
            }
        } else {
            this.setGameStartCanTouch(true, false);
            this.setBallonCanTouch(true);
        }
    };
    public setStartGameShow(e) {
        this.ui.btn_startGame.active = e;
    };
    private playingNode = [];
    public update(e) {
        this.frame_time = e;
        if (this.isPlayingAni) {
            if (TWEENSCALE && this.ui.map.getChildByName('bg2').scale > 0.8) {
                this.ui.map.getChildByName('bg2').scale -= 0.05;
            }
            this.updateTopPro();
            let screenWidth = 600;
            this._earthAnimationArr.forEach(element => {
                let boundingBox = element.node.getBoundingBoxToWorld();
                if (!element.node.active && boundingBox.y > 0 && !(boundingBox.xMax < 0 || boundingBox.xMin > screenWidth)) {
                    if (!this.playingNode.includes(element.node)) {
                        this.playingNode.push(element.node);
                        setTimeout(() => {
                            element.play();
                            element.node.active = true;
                            element.on('finished', () => {
                                let index = this.playingNode.indexOf(element.node);
                                if (index > -1) {
                                    this.playingNode.splice(index, 1);
                                }
                            }, this);
                        }, Math.random() * 400 + 500);
                    }
                } else {
                    if (!this.playingNode.includes(element.node)) {
                        element.node.active = boundingBox.y > 0 && !(boundingBox.xMax < 0 || boundingBox.xMin > screenWidth);
                    }
                }
            });
        } else {
            if (TWEENSCALE && this.ui.map.getChildByName('bg2').scale < 1) {
                this.ui.map.getChildByName('bg2').scale += 0.05;
            }
        }
    };
    public setCityFlagScale() {
        if (this.ui.map.scale == this.minScale) {
            this.ui.cityFlagNode.children.forEach(element => {
                element.scale = .8;
            });
            y.log("设置缩放比例=====", .8);
        }
    };
    public recoverMapShow() {
        var e = d.getTravelLocation();
        if (e) {
            e.current;
            var t = e.location, a = (e.need, e.total);
            this.setCurrentAndNeed();
            this.location = t;
            this.total = a;
            this.setMovePointArr();
            var o = this.movePointArr[this.movePointArr.length - 1];
            // if (o) {
            //     this.ui.aniNode.x = o.x;
            //     this.ui.aniNode.y = o.y;
            // }
            this.updateMapPos();
            this.initTopProShow(true);
            // this.updateCityFlagShow();
            // this.setPandSpineState(true);
            this.lastProgress = this.current;
            d.getTravelEvent() != TravelEvent.NONE && this.dealTravelEvent();
            this.canOpeateMap = true;
            u.isNoGqtcFlag() && this.updateEnterGameBtnShow();
        }
    };
    public updateTopPro() {
        if (null != this.finalPro && null != this.proSpeed) {
            this.ui.pro.getComponent(cc.Sprite).fillRange += this.proSpeed;
            if (this.ui.pro.getComponent(cc.Sprite).fillRange >= this.finalPro) {
                y.log("头部运动完成==进度条完成====", this.current, this.total);
                this.ui.pro.getComponent(cc.Sprite).fillRange = this.finalPro;
            }
        } else y.log("闯关进度设置不正确");
    };
    public setFinalPro() {
        var e = d.isArriveNewCity(), t = (this.current - this.lastProgress) / this.total, a = 1 / this.frame_time;
        this.proSpeed = t / 1.5 / a;
        var o = e ? 1 : this.current / this.total;
        y.log("设置进度条完成的进度====", this.current, this.total, this.lastProgress, t);
        this.finalPro = o;
    };
    public playTopHeadAction() {
        var e = this, t = this.ui.proNode.width * (this.current / this.total), a = .5 * -this.ui.proNode.width + t;
        cc.tween(this.ui.headNode).to(1.5, {
            x: a,
            y: 0
        }).call(function () {
            y.log("头部运动完成", e.current, e.total);
            var t = d.isArriveNewCity();
            e.ui.pro.getComponent(cc.Sprite).fillRange = t ? 1 : e.current / e.total;
        }).start();
    };
    public updateAniPos() {
        var e = this.movePointArr[this.runCount];
        if (e) {
            this.ui.tagNode.setPosition(e);
            var t = this.ui.tagNode.getPosition().subtract(this.ui.aniNode.getPosition()).normalize();
            this.ui.aniNode.x += t.x * this.pandMoveSpeed;
            this.ui.aniNode.y += t.y * this.pandMoveSpeed;
            var a = this.ui.aniNode.position;
            // if (this.calculationDis(a, e) < this.pandMoveSpeed) {
            //     this.ui.aniNode.x = e.x;
            //     this.ui.aniNode.y = e.y;
            //     this.runCount += 1;
            //     if (this.beginCount == this.runCount) {
            //         y.log("当前路径运动完成");
            //         this.runCount = 0;
            //         this.isPlayingAni = false;
            //         this.lastProgress = this.current;
            //         d.isRewardCashAndGold() ? this.setPandSpineState(true) : this.dealRewardFund();
            //     }
            // }
            this.updateMapPos();
        }
    };
    public dealRewardCash() {
        this.clearGuideDraw();
        this.setRollingNoticeParent();
        h.trigger(f.SET_TOP_NODE_CANTOUCH, {
            isCanTouch: false
        });
        var e = d.getRewardCash(), t = d.getRewardGold();

        this.playFlyCash(); 
        return;
        if (t == 0) {
            this.playFlyCash(); 
            return;
        }
        e > 0 && t > 0 ? M.showPage("BigToastPage", {
            reward_cash: e,
            reward_fund: t
        }) : M.showPage("ToastPage", {
            type: 1,
            count: e,
            is_travel: true
        });
    };
    public clearGuideDraw() {
        if (this.ui.drawSpineNode.active || this.ui.drawSpineNode1.active) {
            this.ui.drawSpineNode.active = false;
            this.ui.drawSpineNode1.active = false;
        }
    };
    public setRollingNoticeParent() {
        d.setRollingNoticeParent(this.ui.rollingNode);
    };
    public dealRewardFund() {
        this.setPandSpineState(true);
        var e = d.getRewardGold();
        e > 0 ? M.showPage("ToastPage", {
            type: 2,
            count: e,
            is_travel: true
        }) : this.playFlyFund();
    };
    public dealNewCity() {
        M.showPage("ArriveCityPage");
        _.reportData("arrive_new_city", {
            location: this.location
        });
    };
    public unLockNewCity() {
        var e = this;
        d.dealProLoadBg();
        var t = this.ui.cityFlagNode.children[this.location].getComponent(I);
        s.getInstance().playMusic("newCity");
        t.playUnLockSpine(function () {
            e.dealNewCity();
            e.canOpeateMap = true;
        });
    };
    public checkShowTopNode() {
        var e = d.getOutsideGuideStep(), t = u.isNoGqtcFlag(), a = u.isOptimizeTravelFundFlag();
        if (e >= OutSideLevelGuide.BREAKTHROUGH) {
            var o = d.getTravelRewardInfo(), i = o.gold, r = o.cash, n = "<size=34>" + v.getCashBalance(r) + "</size><size=24>元</size>", l = "<size=34>" + v.getCashBalance(i) + "</size><size=24>元</size>";
            if (a) {
                this.ui.topNode.active = false;
                this.ui.levelCrossingNode.active = true;
                this.ui.fundIcon.active = false;
                this.ui.levelFundLabel.active = false;
                this.ui.levelCashLabel.getComponent(cc.RichText).string = n;
            } else if (t) {
                this.ui.fundIcon.active = true;
                this.ui.levelFundLabel.active = true;
                this.ui.levelCashLabel.getComponent(cc.RichText).string = n;
                this.ui.levelFundLabel.getComponent(cc.RichText).string = l;
                this.ui.topNode.active = false;
                this.ui.levelCrossingNode.active = true;
            } else {
                this.ui.travelCashNode.getComponent(cc.RichText).string = n;
                this.ui.travelFundNode.getComponent(cc.RichText).string = l;
                this.ui.topNode.active = true;
                this.ui.levelCrossingNode.active = false;
            }
        } else {
            this.ui.topNode.active = false;
            this.ui.levelCrossingNode.active = false;
        }
    };
    public setMakeMoneyPos() {
        this.makeMoneyOriginPos = this.ui.makeMoney.getPosition();
    };
    public setEnterGameBtnPos() {
        var e = this;
        this.scheduleOnce(function () {
            e.enterGameOriginPos = e.ui.ejectNode.getPosition();
        });
    };
    public checkShowGameStartNode(e?, t?) {
        this.ui.btn_noGqtc.active = false;
        this.ui.btn_startGame.active = true;
        this.ui.btn_startGame.getComponent(cc.Button).interactable = true;
        this.canOpeateMap = true;
        h.trigger(f.SET_TOP_NODE_CANTOUCH, {
            isCanTouch: true
        });
        return;
        void 0 === e && (e = null);
        void 0 === t && (t = false);
        var a, o = d.getOutsideGuideStep(), i = u.isNoGqtcFlag(), r = u.isOptimizeTravelFundFlag();
        a = r ? p.OutSideLevelGuideExperimentStep.CONTINUE_GAME : OutSideLevelGuide.CONTINUE_GAME;
        if (i) {
            this.ui.btn_startGame.active = false;
            this.ui.btn_noGqtc.active = o >= a;
            this.canOpeateMap = o >= a;
        } else {
            this.ui.btn_noGqtc.active = false;
            this.ui.btn_startGame.active = o >= a;
        }
        y.log("当前新手引导步骤====", o, this.makeMoneyOriginPos);
        var n = C.gameLevel;
        if (t && 2 == n - 1 && o == a && !r) {
            this.ui.btn_startGame.getComponent(cc.Button).interactable = false;
            this.ui.btn_noGqtc.getComponent(cc.Button).interactable = false;
        }
        var l = d.checkGuideClock();
        if (o == (r ? p.OutSideLevelGuideExperimentStep.CONTINUE_GAME : OutSideLevelGuide.CASH_WITHDRAW) && l) {
            this.ui.btn_startGame.getComponent(cc.Button).interactable = false;
            this.ui.btn_noGqtc.getComponent(cc.Button).interactable = false;
        }
        if (e) {
            if (i) {
                this.ui.btn_noGqtc.active = e.guideShow;
                this.ui.btn_noGqtc.getComponent(cc.Button).interactable = true;
                this.ui.ejectNode.setPosition(this.enterGameOriginPos);
                this.canOpeateMap = true;
            } else {
                this.ui.btn_startGame.active = e.guideShow;
                this.ui.makeMoney.x = this.makeMoneyOriginPos.x;
                this.ui.makeMoney.y = this.makeMoneyOriginPos.y;
                this.ui.btn_startGame.getComponent(cc.Button).interactable = true;
                this.canOpeateMap = true;
            }
            h.trigger(f.SET_TOP_NODE_CANTOUCH, {
                isCanTouch: true
            });
        }
    };
    public initTopProShow(e, t?) {
        void 0 === e && (e = false);
        void 0 === t && (t = false);
        var a = d.getCityNameByCityId(this.location - 1), o = d.getCityNameByCityId(this.location);
        if (-1 == this.doneCityArr.indexOf(this.location)) if (e) {
            this.ui.pro.getComponent(cc.Sprite).fillRange = this.current / this.total;
            var i = this.ui.proNode.width * (this.current / this.total), r = .5 * -this.ui.proNode.width + i;
            this.ui.headNode.x = r;
            this.doneCityArr.push(this.location);
        } else {
            this.ui.pro.getComponent(cc.Sprite).fillRange = 0;
            this.ui.headNode.x = .5 * -this.ui.proNode.width;
            this.doneCityArr.push(this.location);
        }
        this.ui.curCityName.getComponent(cc.Label).string = a;
        this.ui.nextCityName.getComponent(cc.Label).string = o;
        var n = MathUtils.accDiv(this.need, this.total), l = this.toDecimal(100 * n) + "%", s = this.need;
        if (!e && t && d.isArriveNewCity()) {
            l = "0%";
            s = 0;
        }
        var c = "", p = u.isNoGqtcFlag(), h = u.isOptimizeTravelFundFlag();
        if (this.location < 31) {
            c = "<color=#3A3D68>再闯</color><color=#FC0B0B> " + s + " </color><color=#3A3D68>关到: " + o + "</color>";
            (p || h) && (c = "<color=#3A3D68>再闯</color><color=#FC0B0B> " + s + " </color><color=#3A3D68>关到</color><color=#FC0B0B> " + o + " </color><color=#3A3D68>，奖励</color>");
        } else {
            u.getIsLcsmzq() && (l = this.toDecimal(100 * d.getToNextCityPercent()) + "%");
            c = "<color=#3A3D68>剩</color><color=#FF1E00> " + l + " </color><color=#3A3D68>的路程到:" + o + "</color>";
            (p || h) && (c = "<color=#3A3D68>剩</color><color=#FC0B0B> " + l + " </color><color=#3A3D68>的路程到</color><color=#FC0B0B> " + o + " </color><color=#3A3D68>，奖励</color>");
        }
        if (p || h) {
            this.ui.levelCrossTips.getComponent(cc.RichText).string = c;
            this.adjustProTipSize(this.ui.levelCrossTips, 1);
        } else {
            this.ui.proTips.getComponent(cc.RichText).string = c;
            this.adjustProTipSize(this.ui.proTips, 2);
        }
    };
    public adjustProTipSize(e, t) {
        var a = e.width, o = 1 == t ? 354 : 270, i = 1;
        a >= o && (i = o / a);
        e.scale = i;
    };
    public playFlyFund(e?) {
        var t = this;
        void 0 === e && (e = null);
        var a = d.gold, o = d.isArriveNewCity(), i = d.getTravelLocation(), r = (i.current,
            i.location), n = i.need, l = i.total;
        if (0 != a) {
            var s = cc.v2(0, 0);
            e && e.pos && (s = e.pos);
            h.trigger(f.SHOWEFFECT_FLYINGRED, {
                startPos: s,
                type: 1,
                callback: function () {
                    t.scheduleOnce(function () {
                        if (o) {
                            t.unLockNewCity();
                            t.lastProgress = null;
                            t.setCurrentAndNeed();
                            t.location = r;
                            t.need = n;
                            t.total = l;
                            y.log("到达新的城市");
                        } else d.isRewardCashAndGold() ? t.scheduleOnce(function () {
                            t.dealTravelEvent();
                        }, 1.5) : t.dealTravelEvent();
                    }, .8);
                    c.updateGoldBalace(a);
                }
            });
        } else if (o) {
            this.unLockNewCity();
            this.lastProgress = null;
            this.setCurrentAndNeed();
            this.location = r;
            this.need = n;
            this.total = l;
            y.log("到达新的城市");
        } else {
            this.canOpeateMap = true;
            d.isRewardCashAndGold() ? this.scheduleOnce(function () {
                t.dealTravelEvent();
            }, 1.5) : this.dealTravelEvent();
        }
    };
    public setGameStartCanTouch(e, t) {
        void 0 === t && (t = true);
        this.ui.btn_startGame.getComponent(cc.Button).interactable = e;
        t || this.playMakeMoney(e);
    };
    public setEnterGameCanTouch(e) {
        this.ui.btn_noGqtc.getComponent(cc.Button).interactable = e;
        this.playEnterGameAction(e);
    };
    public playEnterGameAction(e) {
        var t = this, a = this.ui.btn_noGqtc.active, o = this.ui.btn_noGqtc.y;
        if (a) if (a && e && o == this.enterGameOriginPos.y) {
            this.ui.btn_noGqtc.getComponent(cc.Button).interactable = true;
            this.updateEnterGameBtnShow();
        } else {
            var i = this.enterGameOriginPos, r = i.y - 700, n = i.y, l = e ? n : r, s = e ? {
                easing: "backOut"
            } : {
                easing: "backIn"
            };
            this.ui.btn_noGqtc.getComponent(cc.Button).interactable = false;
            cc.tween(this.ui.ejectNode).to(.4, {
                x: i.x,
                y: l
            }, s).call(function () {
                t.ui.btn_noGqtc.getComponent(cc.Button).interactable = e;
                e ? t.scheduleOnce(t.delayPlayFroceVideo, .5) : t.updateEnterGameBtnShow();
            }).start();
        } else this.ui.btn_noGqtc.getComponent(cc.Button).interactable = true;
    };
    public updateEnterGameBtnShow() {
        return;
        var e = this;
        S.matchGameStart(null, function () {
            var t = C.getGameInfo(), a = t.level, o = t.levelType;
            y.log("更新关卡数据发送请求", t);
            if (o == T.GameLevelType.GoldCoin) {
                e.ui.travelSpineNode.active = false;
                e.ui.btn_des.active = false;
                e.ui.levelDesNode.active = false;
                e.ui.redPaperSpineNode.active = true;
            } else {
                e.ui.travelSpineNode.active = true;
                e.ui.redPaperSpineNode.active = false;
                if (a > 5) {
                    e.ui.levelDesNode.active = true;
                    e.ui.btn_des.active = false;
                    e.ui.level_des.getComponent(cc.Label).string = "" + a;
                } else {
                    e.ui.btn_des.active = true;
                    e.ui.levelDesNode.active = false;
                }
            }
        }, function () { });
    };
    public playMakeMoney(e) {
        var t = this, a = this.makeMoneyOriginPos, o = a.y - 300, i = a.y, r = e ? i : o, n = e ? {
            easing: "backOut"
        } : {
            easing: "backIn"
        };
        this.ui.btn_startGame.getComponent(cc.Button).interactable = false;
        cc.tween(this.ui.makeMoney).to(.4, {
            x: a.x,
            y: r
        }, n).call(function () {
            t.ui.btn_startGame.getComponent(cc.Button).interactable = e;
        }).start();
    };
    public dealTravelEvent() {
        var e = d.getTravelEvent();
        if (e == TravelEvent.MOM_GIVE_MOENY) M.showPage("MomGivesMoneyPage"); else if (e == TravelEvent.SCRAP_CARD) M.showPage("ScrapingCardPage"); else if (e == TravelEvent.OBSTACLE_TIGER || e == TravelEvent.PICKPOCKET) M.showPage("TravelObstracleEventPage", {
            travelEventType: e
        }); else if (e == TravelEvent.SKILL) M.showPage("TravelPropEventPage"); else if (e == TravelEvent.NONE) {
            var t = C.gameLevel, a = u.isNoGqtcFlag(), o = u.isOptimizeTravelFundFlag();
            a && (t = C.gameLevel - 1);
            this.setBallonCanTouch(true);
            if (2 == t && !o) {
                var i = M.hasShowPage("MatchGameTargetPage"), r = M.hasShowPage("MatchGameLoadingPage");
                i || r || this.checkOutSideGuide();
                return;
            }
            if (1 != t) {
                d.checkNextOutSideGuide();
                d.checkShowGameStartPage();
            }
        }
    };
    public updateMapPos() {
        // this.ui.map.y = 0;//e.y;
        // this.ui.map.getChildByName('bg2').position = cc.v3(750 - (C.gameLevel - 1) * 100,0,0)
        // cc.tween(this.ui.map.getChildByName('bg2')).to(2,{position: cc.v3(750 - C.gameLevel * 100,0,0)}).call(()=>{
        //     this.setPandSpineState(true);
        //     this.isPlayingAni = false;
        // }).start()

        // var e = this.getMapMovePos(this.ui.aniNode.getPosition());
        // this.ui.map.x = e.x;
        // this.ui.map.y = 0;//e.y;
        // this.mapLocalPos.x = this.ui.map.x;
        // this.mapLocalPos.y = 0;//this.ui.map.y;
        // this.setMapDonePos(this.mapLocalPos);
    };
    public setMapToBeiJingPos() {
        M.showPage("ClockSuccessToastPage");
        var e = this.mapPointArr[this.mapPointArr.length - 1], t = e[e.length - 1], a = this.getMapMovePos(t);
        a ? cc.tween(this.ui.map).to(2, {
            x: a.x,
            y: a.y
        }, {
            easing: "smooth"
        }).call(function () { }).start() : y.log("获取到北京的坐标不正确=======");
    };
    public getMapMovePos(e) {
        var t = e.x - this.aniLocalX, a = e.y - this.aniLocalY, o = {
            x: 0,
            y: 0
        };
        this.aniLocalX = this.ui.aniNode.x;
        this.aniLocalY = this.ui.aniNode.y;
        if (t > 0) {
            var i = this.mapLocalPos.x - t <= this.mapBoundLimit.left ? this.mapBoundLimit.left : this.mapLocalPos.x - t;
            o.x = i;
        } else {
            var r = this.mapLocalPos.x + Math.abs(t) >= this.mapBoundLimit.right ? this.mapBoundLimit.right : this.mapLocalPos.x + Math.abs(t);
            o.x = r;
        }
        if (a > 0) {
            var n = this.mapLocalPos.y - a <= this.mapBoundLimit.bottom ? this.mapBoundLimit.bottom : this.mapLocalPos.y - a;
            o.y = n;
        } else {
            var l = this.mapLocalPos.y + Math.abs(a) >= this.mapBoundLimit.top ? this.mapBoundLimit.top : this.mapLocalPos.y + Math.abs(a);
            o.y = l;
        }
        return o;
    };
    public setMapLimitGround() {
        var e = this.ui.map.position;
        this.mapLocalPos = e;
        this.ui.map.x = 0;
        this.ui.map.y = 0;
        var t = this.ui.map.convertToWorldSpaceAR(cc.Vec2.ZERO), a = this.ui.mapContainer.convertToNodeSpaceAR(t), o = this.calculateEdge(this.ui.map, this.ui.mapContainer, a);
        o.right = Math.abs(o.right);
        o.top = Math.abs(o.top);
        this.mapBoundLimit = o;
        this.ui.map.position = e;
        this.setMapDonePos(e);
        y.log("设置边界=========", o);
        this.aniLocalX = this.ui.aniNode.x;
        this.aniLocalY = this.ui.aniNode.y;
    };
    public playFlyCash(e?) {
        var t = this;
        void 0 === e && (e = null);
        var a = d.cash, o = cc.v2(0, 0);
        e && e.pos && (o = e.pos);
        0 != a ? h.trigger(f.SHOWEFFECT_FLYINGRED, {
            startPos: o,
            type: 0,
            callback: function () {
                c.updateCashBalace(a);
                t.runPanadaMoveAction();
            }
        }) : this.runPanadaMoveAction();
    };
    public setPandSpineState(e) {
        var t = this.ui.pandSpineNode.getComponent(sp.Skeleton);
        e ? v.playSpine(t, "idle_1", true) : v.playSpine(t, "walk", true);
    };
    public pandaMove(e) {
        void 0 === e && (e = null);
        var t = u.isNoGqtcFlag();
        this.canOpeateMap = false;
        this.resetMapDonePos();
        t ? this.setEnterGameCanTouch(false) : this.setGameStartCanTouch(false, false);
        this.setBallonCanTouch(false);
        this.updateHotAirBallonState();
        this.playFlyCash(e);
    };
    public runPanadaMoveAction() {
        this.setPandSpineState(false);
        h.trigger(f.DAY_AND_FUD_SHOW);
        h.trigger(f.CLICKDAY_PRO);
        this.checkShowGameStartNode();
        // this.checkShowTopNode();
        var e = d.getTravelLocation(), t = (e.current, e.location), a = e.need, o = e.total;
        this.setCurrentAndNeed();
        if (d.isArriveNewCity()) this.current = this.total; else {
            this.total = o;
            this.location = t;
            this.need = a;
        }
        null == this.lastProgress && (this.lastProgress = 0);
        this.initTopProShow(false, true);
        this.setMovePointArr();
        this.playTopHeadAction();
        this.setFinalPro();
        this.isPlayingAni = true;

        this.ui.map.y = 0;//e.y;
        let flags = this.ui.cityFlagNode.children;

        // cc.tween(this.ui.cityFlagNode).call(() => {
        //     for (let t = 0; t < flags.length; t++) {
        //         const i = flags[t].getComponent(I);
        //         i.updategraybg();
        //     }
        // }).to(4, { angle: this.ui.cityFlagNode.angle + 27.7 }).call(() => {
        //     let worldpos = this.node.convertToNodeSpaceAR(this.node.parent.convertToWorldSpaceAR(cc.v3(0, 0, 0)));
        //     this.ui.cityFlagNode.angle = 0;
        //     for (let t = 0; t < flags.length; t++) {
        //         const i = flags[t].getComponent(I);
        //         i.initData({
        //             cityId: t == 3 ? C.gameLevel : t < 3 ? C.gameLevel - Math.abs(3 - t) : C.gameLevel + Math.abs(3 - t),
        //             tagNode: this.ui.aniNode
        //         });
        //     }
        // }).start();

        let bg2: cc.Node = this.ui.map.getChildByName('bg2').getChildByName("earth");
        cc.tween(bg2).call(() => {
            for (let t = 0; t < flags.length; t++) {
                const i = flags[t].getComponent(I);
                i.updategraybg();
            }
        }).to(DUR, { angle: bg2.angle + R }).call(() => {
            this.setPandSpineState(true);
            this.isPlayingAni = false;
            this.ui.cityFlagNode.angle -= R;
            for (let t = 0; t < flags.length; t++) {
                const i = flags[t].getComponent(I);
                i.initData({
                    cityId: t == 3 ? C.gameLevel : t < 3 ? C.gameLevel - Math.abs(3 - t) : C.gameLevel + Math.abs(3 - t),
                    tagNode: this.ui.aniNode
                });
            }
        }).start();
    };

    public setMovePointArr() {
        var e = this.mapPointArr[this.location - 1];
        if (e) if (0 != this.current) {
            var t = this.current / this.total * (e.length - 1), a = this.isOf(t), o = Math.ceil(this.lastProgress / this.total * (e.length - 1));
            if (a) {
                var i = Math.floor(t), r = Math.ceil(t), n = t - i, l = e[i], s = e[r], c = this.getLinePointByPercent(l, s, n);
                if (o == i || o == r) {
                    var u = {
                        x: this.ui.aniNode.position.x,
                        y: this.ui.aniNode.position.y
                    };
                    this.movePointArr = [u, c];
                } else {
                    this.movePointArr = this.getMovePointArr(e, o, i);
                    this.movePointArr.push(c);
                }
            } else this.movePointArr = this.getMovePointArr(e, o, t);
            this.beginCount = this.movePointArr.length;
            this.setPanadaMoveSpeed();
            this.setPandaMoveDirection(this.ui.aniNode.position, this.movePointArr[this.movePointArr.length - 1]);
        } else {
            if (1 == this.location) this.movePointArr = [{
                x: k,
                y: -180
            }]; else {
                var p = this.mapPointArr[this.location - 2];
                p && (this.movePointArr = [p[p.length - 1]]);
            }
            this.beginCount = this.movePointArr.length;
        } else y.log("获取当前路径的点数据错误");
    };
    public setPanadaMoveSpeed() {
        if (!this.movePointArr || this.movePointArr && !this.movePointArr[0]) y.log("移动的坐标获取失败===========不计算速度"); else {
            for (var e = 0, t = 0; t + 1 < this.movePointArr.length; t++) {
                var a = this.movePointArr[t], o = this.movePointArr[t + 1], i = 0;
                a && o && (i = this.calculationDis(a, o));
                e += i;
            }
            e += this.calculationDis(this.ui.aniNode.getPosition(), this.movePointArr[0]);
            this.pandMoveSpeed = e / (1.5 / this.frame_time);
        }
    };
    public getProTime() {
        var e = 0;
        if (!this.movePointArr) {
            y.log("getProTime====获取时间错误");
            return e;
        }
        for (var t = 0; t + 1 < this.movePointArr.length; t++) {
            var a = this.movePointArr[t], o = this.movePointArr[t + 1], i = (this.calculationDis(a, o) - this.pandMoveSpeed) / (this.pandMoveSpeed * (1 / this.frame_time));
            e += i = i <= 0 ? 1 / 60 : i;
        }
        return e;
    };
    public getLinePointByPercent(e, t, a) {
        if (e && t) {
            var o = e.x, i = e.y, r = t.x, n = t.y, l = 0, s = 0;
            if (.5 == a) {
                l = (o + r) / 2;
                s = (i + n) / 2;
            } else {
                l = (r - o) * a + o;
                s = (n - i) * a + i;
            }
            return {
                x: l,
                y: s
            };
        }
        y.log("没有传递两点坐标");
    };
    public getMovePointArr(e, t, a) {
        for (var o = [], i = 0; i < e.length; i++) i >= t && i <= a && o.push(e[i]);
        return o;
    };
    public isOf(e) {
        return String(e).indexOf(".") > -1;
    };
    public checkEeffctTagNode() {
        var e = d.topTagNodeArr;
        if (-1 == e.indexOf(this.ui.btn_startGame)) {
            e.push(this.ui.btn_startGame);
            d.setTopTagArr(e);
        }
    };
    public setEeffectTagNode() {
        var e = d.topTagNodeArr;
        if (-1 == e.indexOf(this.ui.btn_startGame)) {
            var t = {
                type: 2,
                tagNode: this.ui.btn_startGame
            };
            e.push(t);
            d.setTopTagArr(e);
            3 == e.length && h.trigger(f.SET_EFFECT_TARGETS, {
                nodeArr: e
            });
        } else 3 == e.length && h.trigger(f.SET_EFFECT_TARGETS, {
            nodeArr: e
        });
    };
    public toDecimal(e) {
        var t = parseFloat(e);
        if (!isNaN(t)) return Math.round(100 * e) / 100;
    };
    public setMapDonePos(e) {
        if (e) {
            this.mapDonePos.x = e.x;
            this.mapDonePos.y = e.y;
        } else y.log("坐标不正确=======");
    };
    public resetMapDonePos() {
        this.ui.map.x = this.mapDonePos.x;
        this.ui.map.y = 0//this.mapDonePos.y;
        this.ui.map.scale = this.minScale;
        this.setCityFlagScale();
    };
    public updateTopRewardPro() {
        this.ui.travelCashNode.getComponent(cc.Label).string = "y";
        this.ui.travelFundNode.getComponent(cc.Label).string = "y";
    };
    public clickBallon() {
        this.ui.ballonNode.active = false;
        M.showPage("HotAirBallonPage");
    };
    public setBallonCanTouch(e) {
        this.ui.ballonNode.getComponent(cc.Button).interactable = e;
    };
    public updateHotAirBallonState() {
        var e = d.getHotAirBallonFlag(), t = d.getOutsideGuideStep();
        if (0 == e && t >= OutSideLevelGuide.BREAKTHROUGH) {
            if (!this.ui.ballonNode.active) {
                this.ui.ballonNode.active = true;
                this.ui.ballonNode.getComponent(cc.Animation).play("ballon");
            }
        } else this.ui.ballonNode.active = false;
    };
    public guideCityRewardShake() {
        this.ui.cityFlagNode.children.forEach((e) => {
            e.getComponent(I).lockShake();
        });
        this.scheduleOnce(function () { }, 3.2);
    };
    public guideCityMove() {
        var e = this, t = this.mapPointArr[this.mapPointArr.length - 1], a = t[t.length - 1], o = this.getMapMovePos(a);
        if (o) {
            var i = this.ui.drawSpineNode.getComponent(sp.Skeleton);
            this.ui.drawSpineNode.active = true;
            s.getInstance().playMusic("draw_cricle");
            v.playSpine(i, "idle_1", false, function () {
                cc.tween(e.ui.map).to(4, {
                    x: o.x,
                    y: o.y
                }, {
                    easing: "smooth"
                }).call(function () { }).start();
            });
            cc.tween(this.ui.endCityNameNode).delay(4).call(function () {
                s.getInstance().playMusic("draw_cricle");
                e.ui.drawSpineNode1.active = true;
                var t = e.ui.drawSpineNode1.getComponent(sp.Skeleton);
                v.playSpine(t, "idle_1", false, function () { });
            }).start();
        } else y.log("获取到北京的坐标不正确=======");
    };
    public recoverBeginMap() {
        this.clearGuideDraw();
        this.ui.map.x = D.x;
        this.ui.map.y = 0//D.y;
        y.log("收到地图恢复初始位置信息======", this.ui.map.x, this.ui.map.y);
        this.setMapDonePos(D);
    };
    public calculationDis(e, t) {
        var a = e.x - t.x, o = e.y - t.y;
        return Math.sqrt(a * a + o * o);
    };
    public canStartMove(e) {
        var t = e.getStartLocation(), a = e.getLocation();
        return Math.abs(a.x - t.x) > this.moveOffset || Math.abs(a.y - t.y) > this.moveOffset;
    };
    public touchMove(e) {
        var t = this;
        if (this.canOpeateMap && !this.locked) {
            var a = e.getTouches();
            if (this.isStrict) {
                a.filter((e) => {
                    var a = cc.v2(e.getStartLocation()), o = t.node.convertToWorldSpaceAR(cc.Vec2.ZERO);
                    return cc.rect(o.x - t.node.width / 2, o.y - t.node.height / 2, t.node.width, t.node.height).contains(a);
                }).forEach((e) => {
                    0 === t.mapTouchList.filter(function (t) {
                        return t.id === e.getID();
                    }).length && (t.mapTouchList[t.mapTouchList.length] = {
                        id: e.getID(),
                        touch: e
                    });
                });
                a = this.mapTouchList.map((e) => {
                    return e.touch;
                });
            }
            if (a.length >= 2) {
                this.isMoving = true;
                var o, i = a[0], r = a[1], n = cc.v2(i.getDelta()), l = cc.v2(r.getDelta()), s = this.ui.map.convertToNodeSpaceAR(cc.v2(i.getLocation())), c = this.ui.map.convertToNodeSpaceAR(cc.v2(r.getLocation())), u = s.sub(c), p = cc.v2(this.fingerIncreaseRate, this.fingerIncreaseRate), d = n.sub(l).scale(p);
                o = Math.abs(u.x) > Math.abs(u.y) ? (u.x + d.x) / u.x * this.ui.map.scaleX : (u.y + d.y) / u.y * this.ui.map.scaleY;
                var h = c.add(cc.v2(u.x / 2, u.y / 2));
                this.smoothOperate(this.ui.map, h, o);
            } else if (1 === a.length && (this.isMoving || this.canStartMove(a[0]))) {
                this.isMoving = true;
                var f = cc.v2(a[0].getDelta());
                this.dealMove(f, this.ui.map, this.node);
            }
        }
    };
    public adTestCallBack() {
        m.getInstance().adSwitch = !m.getInstance().adSwitch;
        m.getInstance().adSwitch ? this.ui.label_adSwitch.getComponent(cc.Label).string = "广告开关：开" : this.ui.label_adSwitch.getComponent(cc.Label).string = "广告开关：关";
    };
    public touchEnd(e) {
        if (this.canOpeateMap && !this.locked) {
            if ((this.isStrict ? this.mapTouchList : e.getTouches()).length <= 1) {
                if (!this.isMoving) {
                    var t = cc.v2(e.getLocation()), a = this.ui.map.convertToNodeSpaceAR(t);
                    this.dealSelect(a);
                }
                this.isMoving = false;
            }
            this.isStrict && this.removeTouchFromContent(e, this.mapTouchList);
        }
    };
    public touchCancel(e) {
        if (this.canOpeateMap && !this.locked) {
            (this.isStrict ? this.mapTouchList : e.getTouches()).length <= 1 && (this.isMoving = false);
            this.isStrict && this.removeTouchFromContent(e, this.mapTouchList);
        }
    };
    public mouseWheel(e) {
        if (this.canOpeateMap && !this.locked) {
            var t = cc.v2(e.getLocation()), a = e.getScrollY(), o = this.ui.map.scale + a / this.increaseRate, i = this.ui.map, r = i.convertToNodeSpaceAR(t);
            this.smoothOperate(i, r, o);
        }
    };
    public addEvent() {
        // this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
        // this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
        // this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel, this);
        // this.node.on(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheel, this);
        h.listen(f.PANADA_MOVE, this.dealRewardCash, this);
        h.listen(f.FLY_REWARD_CASH, this.pandaMove, this);
        h.listen(f.FLY_REWARD_FUND, this.playFlyFund, this);
        h.listen(f.GUIDE_CITY_REWARD_SHAKE, this.guideCityRewardShake, this);
        h.listen(f.GUIDE_CITY_MOVE, this.guideCityMove, this);
        h.listen(f.RECOVER_BEGIN_MAP, this.recoverBeginMap, this);
        h.listen(f.BLLON_SHOW_STATE, this.updateHotAirBallonState, this);
        h.listen(f.SHOW_GAME_START_PAGE, this.startGameCallback, this);
        h.listen(f.CLOSE_OUTSIDE_GUIDE, this.checkShowGameStartNode, this);
        h.listen(f.INIT_TOP_PRO_SHOW, this.initTopProShow, this);
        h.listen(f.SET_ROLL_NOTICE_PARENT, this.setRollingNoticeParent, this);
        h.listen(f.ENTER_GAME_SHOW, this.showEnterGameBtn, this);
        h.listen(f.ENTER_GAME_CAN_TOUCH, this.canTouchEnterGameBtn, this);
        h.listen(f.UPDATE_COLCK_DAYS, this.onClockDaysUpdate, this);
        h.listen(f.SHOW_BEIJING_FLAG_ANI, this.setMapToBeiJingPos, this);
    };
    public removeEvent() {
        this.node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
        this.node.off(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel, this);
        this.node.off(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheel, this);
        h.ignore(f.PANADA_MOVE, this.dealRewardCash, this);
        h.ignore(f.GUIDE_CITY_REWARD_SHAKE, this.guideCityRewardShake, this);
        h.ignore(f.GUIDE_CITY_MOVE, this.guideCityMove, this);
        h.ignore(f.RECOVER_BEGIN_MAP, this.recoverBeginMap, this);
        h.ignore(f.BLLON_SHOW_STATE, this.updateHotAirBallonState, this);
        h.ignore(f.SHOW_GAME_START_PAGE, this.startGameCallback, this);
        h.ignore(f.CLOSE_OUTSIDE_GUIDE, this.checkShowGameStartNode, this);
        h.ignore(f.FLY_REWARD_CASH, this.pandaMove, this);
        h.ignore(f.FLY_REWARD_FUND, this.playFlyCash, this);
        h.ignore(f.FLY_REWARD_FUND, this.playFlyFund, this);
        h.ignore(f.INIT_TOP_PRO_SHOW, this.initTopProShow, this);
        h.ignore(f.SET_ROLL_NOTICE_PARENT, this.setRollingNoticeParent, this);
        h.ignore(f.ENTER_GAME_SHOW, this.showEnterGameBtn, this);
        h.ignore(f.ENTER_GAME_CAN_TOUCH, this.canTouchEnterGameBtn, this);
        h.ignore(f.UPDATE_COLCK_DAYS, this.onClockDaysUpdate, this);
    };
    public smoothOperate(e, t, a) {
        if (this.minScale <= a && a <= this.maxScale) {
            var o = a - e.scaleX, i = t.scale(cc.v2(o, o)), r = e.position.sub(i), n = this.fingerIncreaseRate.toString(), l = n.split(".")[1] ? n.split(".")[1].length : 0, s = Math.pow(10, 2 + l);
            a = Math.floor(a * s) / s;
            e.scale = a;
            this.dealScalePos(r, e);
            this.minScale == a && this.setCityFlagScale();
        } else a = cc.misc.clampf(a, this.minScale, this.maxScale);
    };
    public dealScalePos(e, t) {
        if (1 === t.scale) e = cc.Vec2.ZERO; else {
            var a = this.node.convertToWorldSpaceAR(e), o = this.node.convertToNodeSpaceAR(a), i = this.calculateEdge(t, this.node, o);
            i.left > 0 && (e.x -= i.left);
            i.right > 0 && (e.x += i.right);
            i.top > 0 && (e.y += i.top);
            i.bottom > 0 && (e.y -= i.bottom);
        }
        t.position = e;
    };
    public dealMove(e, t, a) {
        var o = t.convertToWorldSpaceAR(cc.Vec2.ZERO), i = a.convertToNodeSpaceAR(o);
        i.x += e.x;
        i.y += e.y;
        var r = this.calculateEdge(t, a, i);
        if (r.left <= 0 && r.right <= 0) {
            t.x += e.x;
        }
        if (r.top <= 0 && r.bottom <= 0) {
            t.y += e.y;
        }
    };
    public dealSelect(e) {
        cc.log("click map on (" + e.x + ", " + e.y + ")");
        // this.singleTouchCb && this.singleTouchCb(e);
    };
    public calculateEdge(e, t, a) {
        var o = (t.width - e.width * e.scaleX) / 2, i = (t.height - e.height * e.scaleY) / 2;
        return {
            left: o + a.x,
            right: o - a.x,
            top: i - a.y,
            bottom: i + a.y
        };
    };
    public setStrictPattern(e) {
        this.isStrict = e;
    };
    public getStrictPattern() {
        return this.isStrict;
    };
    public removeTouchFromContent(e, t) {
        for (var a = e.getTouches().map((e) => {
            return e.getID();
        }), o = t.length - 1; o >= 0; --o) a.indexOf(t[o].id) > -1 && t.splice(o, 1);
    };
    public onDestroy() {
        this.removeEvent();
    };
    public delayPlayFroceVideo() {
        if (u.isInsertAdFlagS2()) y.log("命中插屏实验组2不展示插屏广告"); else {
            var e = C._gameLevel, t = v.getLocalData("InsertAdLevel");
            if (t && t == e.toString()) y.log("每一关只播放一次插屏广告"); else {
                var a = d.getInsertAdShowLevel();
                y.log("插屏广告展示的关卡====", a);
                if (e >= a) {
                    y.log("插屏广告=========播放");
                    v.setLocalData("InsertAdLevel", e.toString());
                    m.getInstance().showInsertAd();
                    d.reportVideoBuriedPoint(VideoBuriedPoint.INSERT_AD);
                }
            }
        }
    };
    public setGameTopShowNode() {
        var e = d.getGameShowTopNodeArr();
        if (-1 === e.indexOf(this.ui.topNode)) {
            var t = {
                type: 3,
                topNode: this.ui.topNode
            };
            e.push(t);
        }
        d.setGameShowTopNodeArr(e);
    };
    public setPandaMoveDirection(e, t) {
        // if (e && t) {
        //     var a = "右";
        //     if (t.x - e.x >= 0) this.ui.pandSpineNode.scaleX = 1; else {
        //         this.ui.pandSpineNode.scaleX = -1;
        //         a = "左";
        //     }
        //     y.log("设置熊猫移动方向", a);
        // } else y.log("设置熊猫走动方向传递的坐标不正确");
    };
    static prefabUrl = "assets/resources/prefabs/PandaTravel";
    static className = "PandaTravelCtrl";
    // return r([E, G("UI/prefabs/PandaTravelCtrl")], t);
}
